package com.tanhua.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.domain.Analysis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AnalysisMapper extends BaseMapper<Analysis> {

    /**
     * 查询指定日期的统计信息
     * @param today
     * @return
     */
    @Select("select * from tb_analysis where record_date = #{today}")
    Analysis todaySummary(@Param("today") String today);

    /**
     * #求指定时间段的用户注册数量
     * select sum(num_registered) from tb_analysis where record_date between  "20180101" and "20200101";
     * @param sd
     * @param ed
     * @return
     */
    @Select("select sum(num_registered) from tb_analysis where record_date between  #{sd} and #{ed} ")
    Integer registerBetweenAnd(@Param("sd") String sd, @Param("ed") String ed);

    /**
     * #求指定时间段用户活跃数量
     * select sum(num_active) from tb_analysis where record_date between  "20180101" and "20200101";
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("select sum(num_active) from tb_analysis where record_date between #{startDate} and #{endDate} ")
    Integer activeBetweenAnd(@Param("startDate") String startDate,@Param("endDate") String endDate);

    /**
     * #指定时间段用户活跃数量
     * select sum(num_retention1d) from tb_analysis where record_date between  "20211210" and "20211212";
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("select sum(num_retention1d) from tb_analysis where record_date between #{startDate} and #{endDate} ")
    Integer retentionBetween(@Param("startDate") String startDate,@Param("endDate") String endDate);

    /**
     * 查询指定时间段的统计数据集合
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("select * from tb_analysis where record_date between #{startDate} and #{endDate}")
    List<Analysis> selectBetweenAndDate(@Param("startDate") String startDate, @Param("endDate") String endDate);

    @Select("select  sum(num_registered) from tb_analysis")
    Integer findAllUsers();
}
